/*
************************************************************************************************
* Filename   	: WatchDog.c
* Programmer : JiangJun
* Description	: Process Watch-Dog of STM8L151C8 
* Date           : 2015-01-20
************************************************************************************************
*/


/*
*********************************************************************************************************
*                                                                          INCLUDE FILES
*********************************************************************************************************
*/
#include <string.h>
#include "Dbg.h"
#include "stm8l15x_clk.h"
#include "stm8l15x_iwdg.h"


/*
*********************************************************************************************************
*                                                                        COMPILE SWITCH
*********************************************************************************************************
*/



/*
*********************************************************************************************************
*                                                                      	MACRO DEFINITION
*********************************************************************************************************
*/
	

/*
*********************************************************************************************************
*                                            				     DEFINITIONS / TYPEDEFS
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                                                   GLOBAL VARIABLE & STRUCTURE
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                                                   LOCAL VARIABLE & STRUCTURE
*********************************************************************************************************
*/


/*
*********************************************************************************************************
*                                                                        FUNCTION PROTOTYPE
*********************************************************************************************************
*/


/*---------------------------------------------------------------------------------------------*/
void wdg_InitAndEnable(void)
{
    /* ATTENTION: (1)INSURE LSI is ready; (2)Only enable IWDG can do configuration */
    IWDG_Enable();

    /* Enable write access to IWDG_PR and IWDG_RLR registers */
    IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
  
    /* IWDG configuration: IWDG is clocked by LSI = 38KHz */
    IWDG_SetPrescaler(IWDG_Prescaler_256);
  
    /* IWDG timeout equal to 1724.63 ms (the timeout may varies due to LSI frequency dispersion) */
    /* IWDG timeout=(255 + 1) * Prescaler / LSI = (255 + 1) * 256 / 38000=1724.63 ms */ 
    IWDG_SetReload(0xFF);
  
    /* Reload IWDG counter */
    IWDG_ReloadCounter();
  
    return;
}


/*---------------------------------------------------------------------------------------------*/
void wdg_Feed(void)
{
    /* Reload IWDG counter */
    IWDG_ReloadCounter();

    return;
}


/*--------------------------------------------------------------------------------------------------------
                   									     0ooo
                   								ooo0     (   )
                								(   )     ) /
                								 \ (     (_/
                								  \_)
----------------------------------------------------------------------------------------------------------*/


